home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / MIXTREE.PAK / INIT.C < prev    next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  123 lines

  1. // THIS CODE AND INFORMATION IS PROVIDED "AS IS" WITHOUT WARRANTY OF
  2. // ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO
  3. // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A
  4. // PARTICULAR PURPOSE.
  5. //
  6. // Copyright (C) 1993 - 1995  Microsoft Corporation.  All Rights Reserved.
  7. //
  8. //  MODULE:   init.c
  9. //
  10. //  PURPOSE:   Performs application and instance specific initialization.
  11. //
  12. //  FUNCTIONS:
  13. //    InitApplication() - Initializes window data and registers window.   
  14. //
  15. //  COMMENTS:
  16. //
  17.  
  18. #include <windows.h>            // required for all Windows applications
  19. #include <windowsx.h>
  20. #include "globals.h"            // prototypes specific to this application
  21.  
  22. HINSTANCE hInst;                // current instance
  23.  
  24. char szAppName[9];              // The name of this application
  25. char szTitle[40];               // The title bar text
  26.  
  27. HMENU       hMenu;                  // handle of application menu
  28. HWND        hwndTreeView;           // hwnd of TreeView control
  29. HFONT       hfTVFont;               // handle to font used in TreeView control
  30. HIMAGELIST  hImageList;             // handle to ImageList
  31. long        lCurrentItem;           // currently selected item in mixer list
  32. HTREEITEM   htiCurrentRoot;         // root item of currently selected branch
  33. BOOL        fDisplayAll;            // for View.Display All menu command
  34. BOOL        fCollapseAny;           // for View.Collapse Any menu command
  35. BOOL        fExpandEnabled;         // controls expansion of TreeView items
  36.  
  37. //
  38. //  FUNCTION: InitApplication(HINSTANCE, int)
  39. //
  40. //  PURPOSE: Initializes window data and registers window class.
  41. //
  42. //  PARAMETERS:
  43. //    hInstance - The handle to the instance of this application that
  44. //                is currently being executed.
  45. //    nCmdShow  - Specifies how the main window is to be displayed.
  46. //
  47. //  RETURN VALUE:
  48. //    TRUE  - Success
  49. //    FALSE - Initialization failed
  50. //
  51. //  COMMENTS:
  52. //
  53. //    This function is called at application initialization time.  It
  54. //    performs initialization tasks for the current application instance.
  55. //    Unlike Win16, in Win32, each instance of an application must register
  56. //    window classes.
  57. //
  58. //    In this function, we initialize a window class by filling out a data
  59. //    structure of type WNDCLASS and calling the Windows RegisterClass()
  60. //    function.  Then we create the main window and show it.
  61. //
  62. //
  63.  
  64. BOOL InitApplication(HINSTANCE hInstance, int nCmdShow)
  65. {
  66.     WNDCLASS  wc;           // for registering the window class
  67.     HWND      hwnd;         // local copy of main window handle
  68.  
  69.     // initialize globals
  70.     fDisplayAll = FALSE;
  71.     fCollapseAny = FALSE;
  72.     fExpandEnabled = FALSE;  
  73.  
  74.     // Load the application name and description strings.
  75.     LoadString(hInstance, IDS_APPNAME, szAppName, sizeof(szAppName));
  76.     LoadString(hInstance, IDS_DESCRIPTION, szTitle, sizeof(szTitle));
  77.  
  78.     // Save the instance handle in static variable, which will be used in
  79.     // many subsequence calls from this application to Windows.
  80.     hInst = hInstance; // Store instance handle in our global variable
  81.  
  82.     // Fill in window class structure with parameters that describe the
  83.     // main window.
  84.     wc.style         = CS_HREDRAW | CS_VREDRAW; // Class style(s).
  85.     wc.lpfnWndProc   = (WNDPROC)WndProc;        // Window Procedure
  86.     wc.cbClsExtra    = 0;                       // No per-class extra data.
  87.     wc.cbWndExtra    = 0;                       // No per-window extra data.
  88.     wc.hInstance     = hInstance;               // Owner of this class
  89.     wc.hIcon         = LoadIcon (hInstance, szAppName); // Icon name from .RC
  90.     wc.hCursor       = LoadCursor(NULL, IDC_ARROW); // Cursor
  91.     wc.hbrBackground = (HBRUSH)(COLOR_WINDOW + 1); // Default color
  92.     wc.lpszMenuName  = szAppName;               // Menu name from .RC
  93.     wc.lpszClassName = szAppName;               // Name to register as
  94.  
  95.     // Register the window class and return FALSE if unsuccesful.
  96.     if (!RegisterClass(&wc))   
  97.         return FALSE;    
  98.  
  99.     // Create a main window for this application instance.
  100.     hwnd = CreateWindow(szAppName,           // See RegisterClass() call
  101.                         szTitle,             // Text for window title bar
  102.                         WS_OVERLAPPEDWINDOW, // Window style
  103.                         CW_USEDEFAULT, 0,    // Use default positioning
  104.                         CW_USEDEFAULT, 0,    // Use default size
  105.                         NULL,                // Overlapped has no parent
  106.                         NULL,                // Use the window class menu
  107.                         hInstance,           // This instance owns this window
  108.                         NULL                 // Don't need data in WM_CREATE
  109.     );
  110.  
  111.     // If window could not be created, return "failure"
  112.     if (!hwnd)
  113.         return FALSE;
  114.    
  115.     // Make the window visible; update its client area; and return "success"
  116.     ShowWindow(hwnd, nCmdShow);  // Show the window
  117.     UpdateWindow(hwnd);          // Sends WM_PAINT message
  118.  
  119.     // perform initialization of mixer services or simulation
  120.     return (InitMixer(hwnd));    
  121. }
  122.  
  123.